package com.webserver.http;

import java.util.HashMap;
import java.util.Map;

/**
 * 当前用于定义所有Http协议规定之内容，可被复用
 */
public class HttpContext {

    /**
     * 回车符
     */
    public static final char CR = 13;
    /**
     * 换行符
     */
    public static final char LF = 10;
    /**
     * 资源后缀与MIME类型对应关系
     * key：资源的后缀名  例如：png
     * value: MIME类型  例如：image/png
     */
    private static Map<String,String> mapping = new HashMap<>();

    static{
        initMimeMapping();
    }
    private static void initMimeMapping(){
        mapping.put("html","text/html");
        mapping.put("css","text/css");
        mapping.put("js","application/javascript");
        mapping.put("png","image/png");
        mapping.put("gif","image/gif");
        mapping.put("jpg","image/jpeg");
    }

    /**
     * 根据资源后缀名获取对应的MIME类型
     * @param ext
     * @return
     */
    public static String getMimeType(String ext){
        return mapping.get(ext);
    }

}
